package servlet.news;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import bean.News;

/**
 * Servlet implementation class ModifyNews
 */
@WebServlet("/GetNewsByID")
public class GetNewsByID extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public GetNewsByID() {
		super();
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setContentType("text/html;charset=UTF-8");
		response.setCharacterEncoding("UTF-8");

		int index = Integer.valueOf(request.getParameter("index"));
		int currentPage = Integer.valueOf(request.getParameter("currentPage"));
//		NewsDAO newsDAO = new NewsDAO();
//		List<News> newsList = newsDAO.getCurrentPageNews(currentPage);
		@SuppressWarnings("unchecked")
		List<News> newsList = (List<News>)(request.getSession().getAttribute("newsList"));
		News news = newsList.get(index);
		request.getSession().setAttribute("nowNews", news);
		request.getSession().setAttribute("currentPage", currentPage);
		response.sendRedirect("./jsp/manage/changeNews.jsp");
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		doGet(request, response);
	}

}
